package com.example.demo11.service;

import com.example.demo11.entity.UserBean;
import com.example.demo11.mapper.UserMapper;
import org.apache.catalina.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserService {
    //将dao层属性注入service层
    @Resource
    private UserMapper userMapper;

    public UserBean LoginIn(String username, String password) {
        return userMapper.getInfo(username, password);
    }

    public void Insert(String username, String password) {
        userMapper.saveInfo(username, password);
    }


    // UserService.java 新增方法
    public List<UserBean> getAllUsers() {
        return userMapper.getAllUsers();
    }

    public List<UserBean> getAllUsers(String keyword) {
        if (keyword != null && !keyword.isEmpty()) {
            return userMapper.searchUsers(keyword);
        }
        return userMapper.getAllUsers();
    }

    public void deleteUser(Integer id) {
        userMapper.deleteById(id);
    }

    public UserBean getUserById(Integer id) {
        return userMapper.getById(id);
    }


    public List<UserBean> searchUsers(String keyword) {
        return userMapper.searchUsers(keyword);
    }

    // UserService.java
    public void updateUser(UserBean user) {
        userMapper.updateUser(user); // 调用Mapper更新
    }







}
